package com.sishu.njrtsdms;

import com.sishu.njrtsdms.constant.cache.CacheConstants;
import com.sishu.njrtsdms.core.RedisCache;
import com.sishu.njrtsdms.jooq.codegen.tables.daos.DictDataDAO;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;


@SpringBootApplication
public class NjrtsDmsApplication {

    public static void main(String[] args) {

        SpringApplication.run(NjrtsDmsApplication.class, args);
    }


    @Bean
    CommandLineRunner runner(DictDataDAO dictDataDAO,
                             RedisCache redisCache) {
        return args -> {
            var sysDictKey = CacheConstants.SYS_DICT_KEY;
            if (redisCache.hasKey(sysDictKey))
                redisCache.deleteObject(sysDictKey);
            var dictDataVOList = dictDataDAO.fetchByConditions(null);
            redisCache.setCacheObject(sysDictKey, dictDataVOList);
        };
    }


}
